home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Menu / Menu_DME.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  11.9 KB  |  524 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menu_dme.c
  5.  
  6.     DESCRIPTION
  7.     [X]DME enhancements to menubase.c
  8.  
  9.     NOTES
  10.     that is only a fast hack derived from the original
  11.     menu.c, that supports one menu on all Windows
  12.  
  13.     es ist beabsichtigt, in zukunft nur noch 1 fenster
  14.     mit menues zuzulassen aber dafuer museen erst einmal alle
  15.     windowswitches im [X]DME ueber ene zentrale fktion laufen,
  16.     die dann menu_strip on/off waehlt
  17.  
  18.     BUGS
  19.  
  20.     TODO
  21.     1 I intend to use a Menu only for the actual Window
  22.     2 We must support multiple Menues
  23.     3 we need another MenuToMacro without that damned MENUSTRIP for access from vars
  24.     4 use menubase.fix_items (not ready yet)
  25.  
  26.  
  27.     EXAMPLES
  28.  
  29.     SEE ALSO
  30.  
  31.     INDEX
  32.  
  33.     HISTORY
  34.     20 Dec 1992 b_null created
  35.     24-09-94 b_noll commented out menuload/menusave
  36.     30-10-94 b_noll added menufont
  37.     $Date: 94/07/06 12:06:48 $ last update
  38.  
  39. ******************************************************************************/
  40.  
  41. /**************************************
  42.         Includes
  43. **************************************/
  44. #define  MENU_INTERNAL            /* PATCH_NULL < 24-06-94 */
  45. #include "defs.h"
  46. #include "menubase.h"
  47.  
  48. #include <libraries/gadtools.h>
  49. #include <clib/gadtools_protos.h>
  50. extern struct Library * GadToolsBase;
  51. #include <pragmas/gadtools_pragmas.h>
  52.  
  53. /**************************************
  54.         Globale Variable
  55. **************************************/
  56. Prototype void    menuon         (MENUSTRIP * ms, struct Window * win);
  57. Prototype void    menuoff      (MENUSTRIP * ms, struct Window * win);
  58. Prototype void    menu_strip   (MENUSTRIP * ms, struct Window * Win);
  59. //Prototype void  menuload     (MENUSTRIP * ms,  char * fname);
  60. //Prototype void  menusave     (MENUSTRIP * ms,  char * fname);
  61. Prototype int    fixmenu      (MENUSTRIP * ms, struct Window * win);
  62.  
  63.  
  64. /**************************************
  65.       Interne Defines & Strukturen
  66. **************************************/
  67.  
  68.  
  69. Prototype struct TextAttr  menufont_ta;
  70. struct TextAttr  menufont_ta = {0};
  71. Prototype struct TextFont *menufont;
  72. struct TextFont *menufont    = NULL;
  73.  
  74. /**************************************
  75.         Interne Variable
  76. **************************************/
  77.  
  78.  
  79. /**************************************
  80.        Interne Prototypes
  81. **************************************/
  82.  
  83.  
  84. /*****************************************************************************
  85.  
  86.     NAME
  87.     menuon
  88.  
  89.     PARAMETER
  90.     MENUSTRIP    * ms
  91.     struct Window    * win
  92.  
  93.     RESULT
  94.     -/-
  95.  
  96.     RETURN
  97.     void
  98.  
  99.     DESCRIPTION
  100.     activates the menu definitions of a program; each
  101.     call to menuon eliminates a PRIOR call to menuoff.
  102.  
  103.     NOTES
  104.     Window is not dummy-parameter any more
  105.  
  106.     BUGS
  107.  
  108.     EXAMPLES
  109.  
  110.     SEE ALSO
  111.  
  112.     INTERNALS
  113.     Win war ein Dummy, der schon einmal eingebaut wurde,
  114.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  115.     den Menubar zuzulassen;
  116.     das heisst unter anderem, dass ALLE fenster-manipulationen
  117.     eine spezielle Function aufrufen muessen, die dafuer sogrt,
  118.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  119.     (dafuer bietet sich menu_strip an)
  120.  
  121.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  122.     dies ist zu beruecksichtigen
  123.  
  124.     HISTORY
  125.     20 Dec 1992 b_null  created
  126.  
  127. ******************************************************************************/
  128.  
  129. void menuon (MENUSTRIP * ms, struct Window * win)
  130. {
  131.     ED * ed;
  132.     int  def_too;
  133.  
  134.     if (ms) {
  135.     def_too = (get_menustrip(NULL) == ms);
  136.     if (ms->data && ms->offCount == 1) {
  137.         fixmenu (ms, win); /* !!! we use win here !!! */
  138.  
  139.         /* attach menues */
  140.         for (ed = (ED *)GetHead (&DBase); ed; ed = (ED *)GetSucc ((struct Node *)ed)) {
  141.          /* if (ed->Package == Package)    *//* <-PATCH_PACK */
  142.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  143.         {
  144.             if (!GETF_ICONMODE(ed)) {
  145.             SetMenuStrip (ed->win, ms->data);
  146.  
  147.             Forbid();
  148.             ed->win->Flags &= ~WFLG_RMBTRAP;
  149.             Permit();
  150.             } /* if */
  151.         } /* if */
  152.         } /* for all texts */
  153.     } /* if to be displayed */
  154.  
  155.     if (ms->offCount>0) {
  156.         ms->offCount --;
  157.     } else {
  158.         ms->offCount = 0;
  159.     } /* if menues are off */
  160.     } /* if sensefully called */
  161. } /* menuon */
  162.  
  163.  
  164. /*****************************************************************************
  165.  
  166.     NAME
  167.     menuoff
  168.  
  169.     PARAMETER
  170.     MENUSTRIP    * ms
  171.     struct Window    * win
  172.  
  173.     RESULT
  174.     -/-
  175.  
  176.     RETURN
  177.     void
  178.  
  179.     DESCRIPTION
  180.     inactivates the menudefinitions of a program
  181.     menuoff is stackable that means
  182.     calling menuoff twice needs also two calls to menon
  183.     to be erased
  184.  
  185.     NOTES
  186.     Window is not dummy-parameter any more
  187.  
  188.     BUGS
  189.  
  190.     EXAMPLES
  191.     state a menuoff state b menuon    -> state a
  192.     state a menuon    state a menuoff -> state a
  193.  
  194.     SEE ALSO
  195.  
  196.     INTERNALS
  197.     Win war ein Dummy, der schon einmal eingebaut wurde,
  198.     da ich beabsichtige, nur noch fuer das aktuelle Fenster
  199.     den Menubar zuzulassen;
  200.     das heisst unter anderem, dass ALLE fenster-manipulationen
  201.     eine spezialle Function aufrufen muessen, die dafuer sogrt,
  202.     dass von einem alten Fenster die Menuleiste abgetrennt wird
  203.     (dafuer bietet sich menu_strip an)
  204.  
  205.     zur zeit verwenden wir als default-menustrip jedesmal get_menustip(NULL);
  206.     dies ist zu beruecksichtigen
  207.  
  208.     HISTORY
  209.     20 Dec 1992 b_null  created
  210.  
  211. ******************************************************************************/
  212.  
  213. void menuoff (MENUSTRIP * ms, struct Window * win)
  214. {
  215.     ED * ed;
  216.     int  def_too;
  217.  
  218.     if (ms) {
  219.     def_too = (get_menustrip(NULL) == ms);
  220.     if (ms->offCount == 0) {
  221.         /* detach menues */
  222.         for (ed = (ED *)GetHead(&DBase); ed; ed = (ED *)GetSucc((struct Node *)ed)) {
  223.          /* if (ed->Package == Package)    *//* <-PATCH_PACK */
  224.         if ((ed->menustrip == ms) || (def_too && (ed->menustrip == NULL)))    /* <- PATCH_NEW */
  225.         {
  226.             ClearMenuStrip (ed->win);
  227.             Forbid ();
  228.             ed->win->Flags |= WFLG_RMBTRAP;
  229.             Permit ();
  230.         } /* if */
  231.         } /* for */
  232.     } /* if first menuoff */
  233.     ++ms->offCount;
  234.     } /* if */
  235. } /* menuoff */
  236.  
  237.  
  238. /*****************************************************************************
  239.  
  240.     NAME
  241.     menu_strip
  242.  
  243.     PARAMETER
  244.     MENUSTRIP    * ms
  245.     struct Window    * Win
  246.  
  247.     RESULT
  248.     -/-
  249.  
  250.     RETURN
  251.     void
  252.  
  253.     DESCRIPTION
  254.     that function binds a menustrip to a window
  255.     (or after menuoff, binds no menustrip to a window)
  256.  
  257.     NOTES
  258.       ! in naher Zunkunft wird diese Funktion wohl einen
  259.       ! weiteren Parameter erhalten : status = OFF|ON
  260.     (iconmode ist schliesslich offiziell nicht sichtbar)
  261.  
  262.     BUGS
  263.  
  264.     EXAMPLES
  265.  
  266.     SEE ALSO
  267.  
  268.     INTERNALS
  269.  
  270.     HISTORY
  271.     20 Dec 1992 b_null  created
  272.  
  273. ******************************************************************************/
  274.  
  275. void menu_strip (MENUSTRIP * ms, struct Window * Win)
  276. {
  277.     if (!ms->offCount && ms->data && !GETF_ICONMODE(Ep)) {
  278.     SetMenuStrip (Win, ms->data);
  279.  
  280.     Forbid ();
  281.     Win->Flags &= ~WFLG_RMBTRAP;
  282.     Permit ();
  283.     } else {
  284.     Forbid ();
  285.     Win->Flags |= WFLG_RMBTRAP;
  286.     Permit ();
  287.     } /* if */
  288. } /* menu_strip */
  289.  
  290.  
  291. /*
  292. **  Die Folgenden functionen haben noch keine Header
  293. **  und sind teilweise noch nicht fertig
  294. */
  295.  
  296.  
  297. #if 0
  298. /* die beiden lese/schreib - funktionen konnten stark verkuerzt werden ... */
  299. void menusave (MENUSTRIP * ms, char * name)
  300. {
  301.     FILE * fo;
  302.  
  303.     if ((fo = fopen (name, "w"))) {
  304.     savemenus (ms, fo);
  305.     fclose      (fo);
  306.     } else {
  307. //DEFMESSAGE( __cant_open_outputfile, "%s:\nCan't open file %s for output" )
  308.     error  (_MENU_cant_open_outputfile, CommandName(), name);
  309.     } /* if */
  310. } /* menusave */
  311.  
  312. void menuload (MENUSTRIP * ms, char * name)
  313. {
  314.     int    lineno = 0;
  315.     FILE * fi;
  316.     if ((fi = fopen (name, "r"))) {
  317.     menuoff   (ms, NULL);
  318.     menuclear (ms);
  319.  
  320.     loadmenus (ms, fi, &lineno);
  321.     menuon      (ms, NULL);
  322.     fclose      (fi);
  323.     } else {
  324. //DEFMESSAGE( __cant_open_inputfile, "%s:\nCan't open file %s for input" )
  325.     error (_cant_open_inputfile, CommandName(), name);
  326.     } /* if */
  327.  
  328. } /* menuload */
  329. #endif
  330.  
  331. /*****************************************************************************
  332.  
  333.     NAME
  334.     fixmenu
  335.  
  336.     PARAMETER
  337.     MENUSTRIP     * ms
  338.     struct Window * win
  339.  
  340.     RESULT
  341.     -/-
  342.  
  343.     RETURN
  344.     void
  345.  
  346.     DESCRIPTION
  347.     recalculate the sizes & positions of a menustrip
  348.  
  349.     NOTES
  350.     that function uses GadTools.library
  351.  
  352.     BUGS
  353.  
  354.     EXAMPLES
  355.  
  356.     SEE ALSO
  357.     GadTools/LayoutMenu
  358.  
  359.     INTERNALS
  360.     (ursprueglich liessen wir den kram komplett berechnen, (spagetti)
  361.     dann wurden separate functionen eingefuehrt, die die menuitems
  362.     bzw die subitems rekursiv abarbeiteten)
  363.  
  364.     vorhin las ich jedoch, dass GadTools mit "normalen"
  365.     intuition-menues arbeitet - also kann LayoutMenu() auch
  366.     einen NON-GadTools menustrip verwenden!
  367.  
  368.     wenn aber nun GadTools normale IntuitionMenues verwendet, dann
  369.     kann die verwendete VisualInfo nur als Informationsquelle
  370.     dienen, also kann sie temporaer verwaltet werden
  371.  
  372.     (die Verwendung von GadTools spart > 1/2 kB  oder 130 LoC !)
  373.  
  374.     HISTORY
  375.     03-02-93 b_noll rewritten for use of GadTools
  376.     31-10-94 b_noll added menufont support
  377.  
  378. ******************************************************************************/
  379.  
  380. int fixmenu (MENUSTRIP * ms, struct Window * win)
  381. {
  382.     APTR       vi;                /* VisualInfo for GadTools - probably to get Info 'bout screensize a.s.o. */
  383. #ifdef _DCC
  384.     struct TagItem tags[1] = {{TAG_END,0}}; /* empty tags list for GadTools - varargs stuff is not visible with -mRR */
  385.     vi = GetVisualInfoA (win->WScreen, tags);
  386.     if (!vi)
  387.     return 0;
  388.     LayoutMenusA (ms->data, vi, tags);
  389. #else
  390.     vi = GetVisualInfo (win->WScreen, TAG_END);
  391.     if (!vi)
  392.     return 0;
  393.     LayoutMenus (ms->data, vi,
  394.         menufont? GTMN_TextAttr: TAG_END, &menufont_ta,
  395.         TAG_END);
  396. #endif
  397.     FreeVisualInfo (vi);
  398.     return 1;
  399. } /* fixmenu */
  400.  
  401.  
  402. #if 0
  403.  
  404. static void fixitemfont (struct MenuItem *item, struct TextAttr *font) {
  405.     while (item) {
  406.     if (item->Flags & ITEMTEXT)
  407.         ((struct IntuiText *)item->ItemFill)->ITextFont = font;
  408.     _fixfont(item->SubItem,  font);
  409.     item = item->NextItem;
  410.     } /* while */
  411. } /* fixitemfont */
  412.  
  413. void fixmenufont (struct Menu *menu, struct TextAttr *font) {
  414.     while (menu) {
  415.     _fixfont (menu->FirstItem, font);
  416.     menu = menu->NextMenu;
  417.     } /* while */
  418. } /* fixmenufont */
  419.  
  420. void fixfont (MENUSTRIP *ms, struct TextAttr *font) {
  421.     struct Menu *menu;
  422.     fixmenufont (ms->data, font);
  423.     ms->font = font;
  424. } /* fixfont */
  425.  
  426. #endif
  427.  
  428. /*****************************************************************************
  429.  
  430.     NAME
  431.     currentwindow
  432.  
  433.     PARAMETER
  434.     void;
  435.  
  436.     RESULT
  437.     the current window's menustrip
  438.  
  439.     RETURN
  440.     void*
  441.  
  442.     DESCRIPTION
  443.     An interface to the current ED's menustrip
  444.  
  445.     NOTES
  446.     This function could easiliy be replaced by a macro
  447.  
  448.     HISTORY
  449.     26-08-93    b_noll  created
  450.  
  451. ******************************************************************************/
  452.  
  453. Prototype void *currentmenu  (void);
  454. void *currentmenu (void)
  455. {
  456.     if ((Ep == NULL) || (Ep->menustrip == NULL)) {
  457.     return (get_menustrip (NULL));
  458.     } /* if */
  459.     return (Ep->menustrip);
  460. } /* currentmenu */
  461.  
  462.  
  463. /*****************************************************************************
  464.  
  465.     NAME
  466.     currentmenu
  467.  
  468.     PARAMETER
  469.     void;
  470.  
  471.     RESULT
  472.     the current window
  473.  
  474.     RETURN
  475.     void*
  476.  
  477.     DESCRIPTION
  478.     An interface to the current ED's window
  479.  
  480.     NOTES
  481.     This function should better be replaced by a macro
  482.  
  483.     HISTORY
  484.     26-08-93    b_noll  created
  485.  
  486. ******************************************************************************/
  487.  
  488. Prototype struct Window *currentwindow(void);
  489. struct Window *currentwindow(void)
  490. {
  491.     return (Ep->win);
  492. } /* currentwindow */
  493.  
  494.  
  495.  
  496.  
  497. /******************************************************************************
  498. *****  ENDE menu_dme.c
  499. ******************************************************************************/
  500.  
  501. Prototype void verify_menufont (void);
  502. void verify_menufont (void)
  503. {
  504.     if (menufont) {
  505.     CloseFont (menufont);
  506.     menufont = NULL;
  507.     } /* if */
  508.  
  509.     if (menufont_ta.ta_Name && menufont_ta.ta_YSize) {
  510.     menufont = GetFont (menufont_ta.ta_Name, menufont_ta.ta_YSize);
  511.  
  512.     // GetFont implicitely appends '.font' that bad for Layoutmenu
  513.     if (menufont && strcmp(((struct Node *)menufont)->ln_Name, menufont_ta.ta_Name)) {
  514.         // either ... or
  515.         //menufont_ta.ta_Name = strrep (menufont_ta.ta_Name, ((struct Node *)menufont)->ln_Name);
  516.         CloseFont (menufont);
  517.         menufont = NULL;
  518.     } /* if */
  519.     } /* if */
  520.     do_menuoff();
  521.     do_menuon();
  522. } /* verify_menufont */
  523.  
  524.